package com.reebake.ideal.message.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.message.entity.MessageNotification;
import com.reebake.ideal.message.service.MessageNotificationService;
import com.reebake.ideal.message.vo.MessageNotificationQueryParamVO;
import com.reebake.ideal.message.vo.MessageNotificationVO;

 /**
 * 消息通知控制层
 */
@Tag(name = "消息通知对象功能接口")
@RestController
@RequestMapping("/message/notification")
public class MessageNotificationController {
    @Autowired
    private MessageNotificationService messageNotificationService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<MessageNotificationVO> page(@RequestBody MessageNotificationQueryParamVO queryParam) {
        LambdaQueryWrapper<MessageNotification> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getTitle()), MessageNotification::getTitle, queryParam.getTitle());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getReceiverId()), MessageNotification::getReceiverId, queryParam.getReceiverId());
        
        queryParam = messageNotificationService.page(queryParam, queryWrapper);
        
        return queryParam.to(MessageNotificationVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param messageNotification 实例对象
     */
    @Operation(summary = "保存或更新数据")
    @PostMapping("save")
    public void save(@RequestBody MessageNotificationVO messageNotification) {
        messageNotificationService.saveOrUpdate(BeanUtil.copyProperties(messageNotification, MessageNotification.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param messageNotificationIds 主键
     */
    @Operation(summary = "通过主键批量删除")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> messageNotificationIds) {
        messageNotificationService.removeByIds(messageNotificationIds);
    }
}